﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
Copyright 2010 Mirosław M. Mączka

This file is part of Flac2Wma.

    Flac2Wma is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
namespace Flac2Wma
{

    public class MI_connector
    {
        //
        MediaInfoLib.MediaInfo32 mi32 = null;
        //
        public MI_connector()
        {
                mi32 = new MediaInfoLib.MediaInfo32();
        }
        //
        public bool getPlayTimeForFile(string fileName, out int nTicks)
        {
            nTicks = -1;
            //
            try
            {
                if (!mi32.Open(fileName)) return false;
                //
                getPlayTime(out nTicks);
                //
                mi32.Close();
                
            }
            catch
            {
                return false;
            }
            //
            return true;
        }
        //
        public bool getPlayTime(out int nTicks)
        {
            string s = "";
            s = mi32.getAudioPlaytime();
            nTicks = -1;
            //
            if ("" == s) return false;
            //
            return int.TryParse(s, out nTicks);
        }        //
    }

}
